package com.cskaoyan.config;

import com.cskaoyan.service.UserService;
import org.springframework.aop.framework.ProxyFactoryBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;

/**
 * @author stone
 * @date 2022/07/07 11:21
 */
@Configuration
@ComponentScan("com.cskaoyan")
public class SpringConfiguration {

    // 通过ProxyFactoryBean注册代理组件
    @Bean
    public ProxyFactoryBean userServiceProxy(UserService userService) {
        ProxyFactoryBean proxyFactoryBean = new ProxyFactoryBean();
        // 设置委托类组件 → 划定了增强范围
        proxyFactoryBean.setTarget(userService);
        // 提供的是字符串类型的值，如果提供了字符串作为组件id，能不能从容器中获得这个组件
        // 如果ProxyFactoryBean中包含容器和组件id，能够获得该组件呢
        // 而如何能够获得容器 → Aware
        proxyFactoryBean.setInterceptorNames("countTimeAdvice");
        return proxyFactoryBean;
    }
}
